-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand VersoView to include more APIs #275
base: main
Are you sure you want to change the base?
Conversation
…pand-versoview
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To help with the review process, have left a few remarks
src/verso.rs
Outdated
if let Some((window, _)) = self.windows.get_mut(&window_id) { | ||
if let WindowEvent::CloseRequested = event { | ||
if let Some(to_controller_sender) = &self.to_controller_sender { | ||
if window.event_listeners.on_close_requested { | ||
if let Err(error) = | ||
to_controller_sender.send(ToControllerMessage::OnCloseRequested) | ||
{ | ||
log::error!("Verso failed to send WebResourceRequested to controller: {error}") | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
// self.windows.remove(&window_id); | ||
compositor.maybe_start_shutting_down(); | ||
} else { | ||
window.handle_winit_window_event( | ||
&self.constellation_sender, | ||
compositor, | ||
&event, | ||
); | ||
return window.resizing; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the controller said they want to handle the CloseRequested
event, send it to the controller instead of handling it ourselves
pub fn get_size(&self) -> Result<PhysicalSize<u32>, Box<ipc_channel::ErrorKind>> { | ||
self.sender.send(ToVersoMessage::GetSize)?; | ||
let (sender, receiver) = std::sync::mpsc::channel(); | ||
self.event_listeners | ||
.size_response | ||
.lock() | ||
.unwrap() | ||
.replace(sender); | ||
Ok(receiver.recv().unwrap()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things like these work like this:
- we send
ToVersoMessage::GetSize
here, and wait with a blocking receive - versoview receives this message and push send us back a
ToControllerMessage::GetSizeResponse
- We receive this message from the message look created in the beginning
- Our message look send the message to us
- We receive this message and return it to the caller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we ensure ToControllerMessage::GetSizeResponse
will be sent after the size_response
is set? Since they are running in different process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no, we can ensure it's always sent in normal cases but if the other side crashed or something when wrong during the IPC calls this will go wrong, but I don't think we can do much about those cases anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments. Btw, do we have examples to test these functions?
_ => {} | ||
} | ||
} | ||
|
||
fn first_webview_id(&self) -> Option<TopLevelBrowsingContextId> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since ToVersoMessage
uses many of the first available Window
, maybe we can add a first_window
here and a current_tab_id
method in Window
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, are we sure there can be only one Window
in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
ToVersoMessage
uses many of the first availableWindow
, maybe we can add afirst_window
here and acurrent_tab_id
method inWindow
.
Yeah, I could add one
Also, are we sure there can be only one
Window
in this case?
Yes
} | ||
ToVersoMessage::GetSize => { | ||
if let Some((window, _)) = self.windows.values_mut().next() { | ||
if let Err(error) = self.to_controller_sender.as_ref().unwrap().send( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we handle the unwrap
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_controller_sender
should always present as this function is only called when we received messages from the other side, I can put it in the beginning of this function though
pub fn get_size(&self) -> Result<PhysicalSize<u32>, Box<ipc_channel::ErrorKind>> { | ||
self.sender.send(ToVersoMessage::GetSize)?; | ||
let (sender, receiver) = std::sync::mpsc::channel(); | ||
self.event_listeners | ||
.size_response | ||
.lock() | ||
.unwrap() | ||
.replace(sender); | ||
Ok(receiver.recv().unwrap()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we ensure ToControllerMessage::GetSizeResponse
will be sent after the size_response
is set? Since they are running in different process.
// and send ConstellationMsg::AllowNavigationResponse there if the call succeed | ||
return; | ||
} | ||
} | ||
} | ||
send_to_constellation(sender, ConstellationMsg::AllowNavigationResponse(id, true)); | ||
} | ||
EmbedderMsg::WebResourceRequested(_webview_id, request, sender) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we should add a feature flag in the future as this kind of logic growing up will increasing maintenance effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be hard to keep everything related to the webview controllers in a feature flag as it's quite integrated, but we could try that in a future PR
I do have some examples in the https://github.com/versotile-org/tauri-runtime-verso repo but not here though, for a quick test you should be able to use those function in |
Added control APIs:
exit
execute_script
set_size
set_position
set_maximized
set_minimized
set_fullscreen
set_visible
get_size
get_position
is_maximized
is_minimized
is_fullscreen
is_visible
get_scale_factor
get_current_url
start_dragging
Added init settings:
size
position
maximized
resources_directory
userscripts_directory
devtools_port
Other APIs:
on_web_resource_requested
on_close_requested